import { createRouter, createWebHistory } from 'vue-router'
import BasicLayout from '@/layouts/BasicLayout.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      component: BasicLayout,
      redirect: '/dashboard',
      children: [
        {
          path: 'dashboard',
          name: 'Dashboard',
          component: () => import('@/views/Dashboard.vue'),
          meta: { title: '仪表盘' },
        },
        {
          path: 'life-entities',
          name: 'LifeEntities',
          component: () => import('@/views/LifeEntities/index.vue'),
          meta: { title: '生命体管理' },
        },
        {
          path: 'life-entities/:id',
          name: 'LifeEntityDetail',
          component: () => import('@/views/LifeEntities/Detail.vue'),
          meta: { title: '生命体详情' },
        },
        {
          path: 'network',
          name: 'Network',
          component: () => import('@/views/Network/index.vue'),
          meta: { title: '网络关系' },
        },
        {
          path: 'monitoring',
          name: 'Monitoring',
          component: () => import('@/views/Monitoring/index.vue'),
          meta: { title: '实时监控' },
        },
        {
          path: 'network-demo',
          name: 'NetworkDemo',
          component: () => import('@/views/NetworkDemo.vue'),
          meta: { title: '网络可视化演示' },
        },
      ],
    },
    {
      path: '/login',
      name: 'Login',
      component: () => import('@/views/Login.vue'),
      meta: { title: '登录' },
    },
    {
      path: '/:pathMatch(.*)*',
      name: 'NotFound',
      component: () => import('@/views/404.vue'),
      meta: { title: '页面不存在' },
    },
  ],
})

// 路由守卫
router.beforeEach((to, from, next) => {
  // 设置页面标题
  if (to.meta?.title) {
    document.title = `${to.meta.title} - LifeVerse`
  }

  // 这里可以添加认证逻辑
  next()
})

export default router
